package Search.SearchTest;

import Algorithm.Search.BinarySearch;
import Algorithm.Search.LinearSearch;
import Algorithm.Sort.Template;
import Utils.ArrUtil;

import java.util.List;

/**
 * 测试四种查找
 */
public class Test {

    public static void main(String[] args) {
        int testSize = 10000;
        int[] arr = Template.getIntData(testSize);
        System.out.println("测试量" + testSize);
        ArrUtil.show(arr);//输出原数组
        int a = (int) (Math.random() * testSize);
        System.out.println("测试:查找" + a);


        //查找算法(1) 线性查找测试
        System.out.println("1.线性查找");
        List<Integer> index = LinearSearch.search(arr, a);

        //查找算法(2) 二分查找测试
        //System.out.println("2.二分查找");
        //List<Integer> index = BinarySearch.search(arr, a);


        if (index.size() == 0) System.out.println("无该元素");
        assert index.size() != 0;//大小不为0
        for (int i = 0; i < index.size(); i++) System.out.println("下标为 " + index.get(i));
        for (int i = 0; i < index.size(); i++)
            System.out.println("数组实际元素 arr[" + index.get(i) + "]=" + arr[index.get(i)]);
    }
}
